load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:java_grpc_library.bzl", "java_grpc_library")

# Mirrors the dependencies included in the artifact on Maven Central for usage
# with maven_install's override_targets. Should only be used as a dep for
# pre-compiled binaries on Maven Central.
java_library(
    name = "xds_maven",
    visibility = ["//visibility:public"],
    exports = [
        ":orca",
        ":xds",
    ],
)

java_library(
    name = "xds",
    srcs = glob(
        [
            "src/main/java/**/*.java",
            "third_party/zero-allocation-hashing/main/java/**/*.java",
        ],
        exclude = ["src/main/java/io/grpc/xds/orca/**"],
    ),
    resources = glob([
        "src/main/resources/**",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":envoy_service_discovery_v3_java_grpc",
        ":envoy_service_load_stats_v3_java_grpc",
        ":envoy_service_status_v3_java_grpc",
        ":orca",
        ":xds_protos_java",
        "//:auto_value_annotations",
        "//alts",
        "//api",
        "//auth",
        "//context",
        "//core:internal",
        "//netty",
        "//services:metrics",
        "//services:metrics_internal",
        "//stub",
        "//util",
        "@com_google_googleapis//google/rpc:rpc_java_proto",
        "@com_google_protobuf//:protobuf_java",
        "@com_google_protobuf//:protobuf_java_util",
        "@maven//:com_google_auth_google_auth_library_oauth2_http",
        artifact("com.google.code.findbugs:jsr305"),
        artifact("com.google.code.gson:gson"),
        artifact("com.google.errorprone:error_prone_annotations"),
        artifact("com.google.guava:guava"),
        artifact("com.google.re2j:re2j"),
        artifact("io.netty:netty-buffer"),
        artifact("io.netty:netty-codec"),
        artifact("io.netty:netty-common"),
        artifact("io.netty:netty-handler"),
        artifact("io.netty:netty-transport"),
    ],
)

java_proto_library(
    name = "xds_protos_java",
    deps = [
        "@com_github_cncf_xds//udpa/type/v1:pkg",
        "@com_github_cncf_xds//xds/type/v3:pkg",
        "@envoy_api//envoy/admin/v3:pkg",
        "@envoy_api//envoy/config/cluster/v3:pkg",
        "@envoy_api//envoy/config/core/v3:pkg",
        "@envoy_api//envoy/config/endpoint/v3:pkg",
        "@envoy_api//envoy/config/listener/v3:pkg",
        "@envoy_api//envoy/config/rbac/v3:pkg",
        "@envoy_api//envoy/config/route/v3:pkg",
        "@envoy_api//envoy/extensions/clusters/aggregate/v3:pkg",
        "@envoy_api//envoy/extensions/filters/common/fault/v3:pkg",
        "@envoy_api//envoy/extensions/filters/http/fault/v3:pkg",
        "@envoy_api//envoy/extensions/filters/http/gcp_authn/v3:pkg",
        "@envoy_api//envoy/extensions/filters/http/rbac/v3:pkg",
        "@envoy_api//envoy/extensions/filters/http/router/v3:pkg",
        "@envoy_api//envoy/extensions/filters/network/http_connection_manager/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/least_request/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/pick_first/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/ring_hash/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/round_robin/v3:pkg",
        "@envoy_api//envoy/extensions/load_balancing_policies/wrr_locality/v3:pkg",
        "@envoy_api//envoy/extensions/transport_sockets/http_11_proxy/v3:pkg",
        "@envoy_api//envoy/extensions/transport_sockets/tls/v3:pkg",
        "@envoy_api//envoy/service/discovery/v3:pkg",
        "@envoy_api//envoy/service/load_stats/v3:pkg",
        "@envoy_api//envoy/service/status/v3:pkg",
        "@envoy_api//envoy/type/matcher/v3:pkg",
        "@envoy_api//envoy/type/v3:pkg",
    ],
)

java_grpc_library(
    name = "envoy_service_discovery_v3_java_grpc",
    srcs = ["@envoy_api//envoy/service/discovery/v3:pkg"],
    deps = [":xds_protos_java"],
)

java_grpc_library(
    name = "envoy_service_load_stats_v3_java_grpc",
    srcs = ["@envoy_api//envoy/service/load_stats/v3:pkg"],
    deps = [":xds_protos_java"],
)

java_grpc_library(
    name = "envoy_service_status_v3_java_grpc",
    srcs = ["@envoy_api//envoy/service/status/v3:pkg"],
    deps = [":xds_protos_java"],
)

java_library(
    name = "orca",
    srcs = glob([
        "src/main/java/io/grpc/xds/orca/*.java",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":orca_protos_java",
        ":xds_service_orca_v3_java_grpc",
        "//api",
        "//context",
        "//core:internal",
        "//protobuf",
        "//services:metrics",
        "//services:metrics_internal",
        "//stub",
        "//util",
        "@com_google_protobuf//:protobuf_java_util",
        artifact("com.google.code.findbugs:jsr305"),
        artifact("com.google.guava:guava"),
    ],
)

java_proto_library(
    name = "orca_protos_java",
    deps = [
        "@com_github_cncf_xds//xds/data/orca/v3:pkg",
        "@com_github_cncf_xds//xds/service/orca/v3:pkg",
    ],
)

java_grpc_library(
    name = "xds_service_orca_v3_java_grpc",
    srcs = ["@com_github_cncf_xds//xds/service/orca/v3:pkg"],
    deps = [":orca_protos_java"],
)
